//array, like std:vector but allocated once, and w/o run-time checking
//$Id: array.h 395 2010-03-26 14:01:03Z Oleg.Bulychov $
#pragma once

#include "src/heo/include/reflection.h"

template<class T>
class Array
{
    T*      pt_;
    size_t  dim_;
public:
    Array(): pt_(NULL), dim_(0)
    {}

    Array(Array const& right)
    {
        dim_ = right.dim_;
        pt_ = new T[dim_];
        memcpy(pt_, right.pt_, dim_ * sizeof(T));
    }

    ~Array()
    {
        delete[] pt_;
    }

    Array& operator = (Array const& right)
    {
        if (this != &right)
        {
            Array tmp(right);
            tmp.swap(*this);
        }
        return *this;
    }

    void swap(Array& right)
    {
        std::swap(pt_, right.pt_);
        std::swap(dim_, right.dim_);
    }

    size_t size() const { return dim_; }

    void set_Size(size_t dim)
    {
        if (dim != dim_)
        {
            dim_ = dim;
            if (pt_)
            {
                delete[] pt_;
                pt_ = NULL;
            }
            if (dim)
                pt_ = new T[dim];
        }
    }

    T& operator[](ptrdiff_t i)
    {
        ASSERT_((size_t)i < dim_);
        return pt_[i];
    }

    T const& operator[](ptrdiff_t i) const
    {
        ASSERT_((size_t)i < dim_);
        return pt_[i];
    }

    template<class V>
    void accept(V& v)
    {
        //TODO fix me
        v(pt_, 0, meta::ptr_size(dim_));
    }
};

//EOF!
